import Dialog from '../miniprogram_npm/@vant/weapp/dialog/dialog';

export function throttle(fn, delay) {
  var self = this;
  var oldDate = Date.now();
  return function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
      args[_i] = arguments[_i];
    }
    var newDate = Date.now();
    if (newDate - oldDate > delay) {
      fn.apply(self, args);
      oldDate = Date.now();
    }
  };
};


export function hasToken() {
  var is_login = wx.getStorageSync('uinfo');
  if (is_login = '' || is_login != null || is_login != undefined) {
    return false
  } else {
    return true
  }
}

export function dialog(title, message) {
  Dialog.confirm({
    title: title,
    message: message
  }).then(() => {
    wx.switchTab({
      url: '/pages/user/user'
    })
  }).catch(() => { })
}

export function checkLogin() {
  if (hasToken()) return true

  dialog('提示', '暂未登录,前往登录')
  return false
}
export function showTan() {
  dialog('提示', '暂未登录,前往登录')
}
